package xin.qixia.client.runner;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import xin.qixia.client.mapper.RobotMapper;
import xin.qixia.common.core.AutoQueryWrapper;
import xin.qixia.robot.core.domain.Robot;
import xin.qixia.robot.core.factory.RobotClientFactory;

import java.util.List;

/**
 * 初始化 Robot 模块对应业务数据
 *
 * @author Lion Li
 */
@Slf4j
@RequiredArgsConstructor
@Component
public class RobotApplicationRunner implements ApplicationRunner {

    private final RobotMapper robotMapper;

    private final RobotClientFactory factory;

    @Override
    public void run(ApplicationArguments args) {
        List<Robot> robotList = robotMapper.selectList(new AutoQueryWrapper<Robot>()
                .eq(Robot::getStatus, true));
        robotList.forEach(factory::register);
    }

}
